package com.weilele.leisure.time

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.exoplayer2.MediaItem
import com.weilele.base.library.BaseBindingFragment
import com.weilele.base.library.BaseFragment
import com.weilele.base.library.FragmentContainerActivity
import com.weilele.leisure.time.databinding.FragmentVideoTestBinding
import com.yizisu.playerlibrary.IYzsPlayer


class VideoTestFragment : BaseBindingFragment<FragmentVideoTestBinding>() {
//    private val url = "http://ivi.bupt.edu.cn/hls/cctv6hd.m3u8"
    private val url = "http://mirror.aarnet.edu.au/pub/TED-talks/911Mothers_2010W-480p.mp4"

    companion object {
        fun start(appCompatActivity: AppCompatActivity) {
            FragmentContainerActivity.start<VideoTestFragment>(appCompatActivity)
            appCompatActivity.finish()
        }
    }


    private val player by lazy { IYzsPlayer.invoke<IYzsPlayer.Model>(this,true) }

    override fun initUi(savedInstanceState: Bundle?) {
        super.initUi(savedInstanceState)
        mBinding.root.setPlayerAndInitHelper(player)
        player.prepare(mutableListOf(
            object : IYzsPlayer.Model() {
                override fun onMediaItem(uriCall: (MediaItem?, Throwable?, Boolean) -> Unit) {
                    uriCall.invoke(MediaItem.fromUri(url), null, false)
                }

                override fun getTitle(): CharSequence? {
                    return "我是标题哈哈哈哈"
                }
            }
        ))
    }

}